<template>
  <div>
    <!-- 为 ECharts 准备一个具备大小（宽高）的 DOM -->
    <div id="main" style="width: 100%;height:600px;"></div>
  </div>
</template>
<script>
import { mapGetters, mapActions } from "vuex";
// import echarts from "echarts";
export default {
  components: {},
  computed: {
    ...mapGetters({
      list: "cate/list",
    }),
  },
  methods: {
    ...mapActions({
      reqList: "cate/reqlist",
    }),
  },
  mounted() {
    this.reqList();
  },
  watch: {
    list: {
      handler() {
        if (this.list.length > 0) {
          // 基于准备好的dom，初始化echarts实例
          var myChart = require("echarts").init(
            document.getElementById("main")
          );

          // 指定图表的配置项和数据
          var option = {
            color: ["#c23531", "#2f4554", "#61a0a8"],
            title: {
              text: "商品分类数据",
            },
            tooltip: {},
            legend: {
              data: ["子类数量"],
            },
            xAxis: {
              data: this.list.map(item=>item.catename),
            },
            yAxis: {},
         
            series: [
              {
                name: "子类数量",
                type: "bar",
                data:this.list.map(item=>item.children?item.children.length:0),
              },
            ],
          };
          myChart.setOption(option);
        }
      },
      deep: true,
    },
  },
};
</script>
<style lang="less" scoped>
</style>